#include "MoveTo.h"
#include "T_Scene.h"

MoveTo *MoveTo::create(const Gdiplus::PointF &desti,float dur){
	MoveTo *move=new MoveTo();
	move->setDuration(dur);
	move->m_EndPos=desti;
	return move;
}

bool MoveTo::init(T_Node *node){
	if(ActionInterval::init(node)){
		m_StartPos=node->getPosition();
		m_Delta=(m_EndPos-m_StartPos);
		m_Delta.X/=m_Duration;
		m_Delta.Y/=m_Duration;
		return true;
	}
	return false;
}

void MoveTo::startWithTarget(T_Node *node){
	if(!init(node))return;
	T_Scene *scene=node->getScene();
	if(NULL==scene)return;
	scene->getActionPool().removeAll(node,getActionType());
	scene->getActionPool().add(this);
}

void MoveTo::update(int dt){
	ActionInterval::update(dt);
	if(m_Target==NULL){return;}
	Gdiplus::PointF offset=m_Delta;
	offset.X*=dt;
	offset.Y*=dt;
	m_Target->setPosition(m_Target->getPosition()+offset);
}